package com.szbmyoubao.app.view.dialog

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.ellecity06.common.base.BaseDialogFragment
import com.ellecity06.common.ktx.toast
import com.ellecity06.cwhiskymall.databinding.DialogBindBinding

/**
 * @author ellecity06
 * @time 2025/3/21 16:26
 * @des
 */
fun Fragment.showBindDialog( title: String= "邀请码",text: String?= null, enable: Boolean=true, block:(String)-> Unit){
    BindDialog(title,text,enable,block).show(childFragmentManager,"BindDialog")
}
class BindDialog(val title: String= "邀请码", val text: String?=null, val enable: Boolean=true,val block:(String)-> Unit) : BaseDialogFragment<DialogBindBinding>() {
    override fun inflateBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): DialogBindBinding {
        return DialogBindBinding.inflate(inflater, container, false)
    }

    override fun initialize() {
        binding.tvTitle.text =title
        binding.etCode.hint = "请输入${title}"
        binding.etCode.isEnabled = enable
        binding.etCode.setText(text?:"")
        binding.tvDgcCancel.setOnClickListener {
            dismiss()
        }
        binding.tvDgcConfirm.setOnClickListener {
            val text = binding.etCode.text.toString().trim()
            if (text.isEmpty()) {
                toast("内容不可为空")
                return@setOnClickListener
            }
            block.invoke(text)
            dismiss()

        }

    }
}